<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;
use common\helper\HashHelper;
$time = time();
$key = HashHelper::getUploadHash($time);
/* @var $this yii\web\View */
/* @var $model common\models\DayTry */
/* @var $form yii\widgets\ActiveForm */
?>

<style>
.field-daytry-recommend_time .input-group{width:300px;}
.field-daytry-status{width:300px;}
</style>
<div class="day-try-form">

    <?php $form = ActiveForm::begin(['id' => 'form1']); ?>

    <?= $form->field($model, 'product_id')->textInput() ?>

    <?= $form->field($model, 'pic')->widget('yidashi\webuploader\WebBatchUploader',['server'=>common\helper\UrlManager::createUrl(Yii::$app->params['domains']['upload'],['upload/webupload','time'=>$time,'key'=>$key]),'options'=>['number'=>1]]) ?>

    <?= $form->field($model, 'status')->dropDownList([ '不显示', '显示']) ?>

    <?= $form->field($model, 'recommend_time')->widget(DateTimePicker::className(), 
        [
        'template'=>"{input}{reset}{button}",
        'clientOptions' => [
            'autoclose' => true,
            'linkFormat' => 'yyyy-MM-dd', // if inline = true
            //'format' => 'yyyy-mm-dd', // if inline = false
            'todayBtn' => true,
            'pickerPosition'=>"bottom-left",
            'language'=>'zh-CN',
            'minView'=>'hour'
        ]    
    ]) ?>
    

    <div class="form-group">
        <?= Html::input('hidden', 'form_check', $model->isNewRecord ? 0 : 1, ['id'=>'form_check']); ?>
        <?= Html::input('hidden', 'time_check', 0, ['id'=>'time_check']); ?>
        <?= $model->isNewRecord ? $form->field($model, 'add_time')->hiddenInput(['value'=>date('Y-m-d H:i:s')])->label(false) : '' ?>
        <?= $model->isNewRecord ? $form->field($model, 'add_user')->hiddenInput(['value'=>Yii::$app->session['admin_name']])->label(false)  : '' ?>
        <?= Html::submitButton($model->isNewRecord ? '新建' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('js');?>
<script>
$(function(){
    $('#daytry-product_id').change(function(){
           $.post("<?=Yii::$app->urlManager->createUrl('day-try/get-goods-info')?>",{product_id: $('#daytry-product_id').val(), rnd:Math.random()},  function(json) {
               if(json.flag == 1)
               {
                   $('#form_check').val(1);
                   return false;
               }else
               {
                   alert(json.msg);
                   $('#form_check').val(0);
                   return false;
               }
            },"json");
    });
});


$("#form1").submit(function(){
        
        if($('#form_check').val() == 0)
        {
            alert('货品ID不存在');
            return false;  
        }
//        var rectime=$("#daytry-recommend_time").val();  //推荐时间
//        rectime = new Date(rectime.replace("-", "/").replace("-", "/")); 
//        var today = new Date();
//        if(rectime < today)
//        {
//            alert('推荐时间不能小于系统时间');
//            return false;  
//        }
//        
//        $.post("<?=Yii::$app->urlManager->createUrl('day-try/check-time')?>",{recommend_time: $('#daytry-recommend_time').val(), rnd:Math.random()},  function(json) {
//               if(!json.flag)
//               {
//                   alert('推荐时间已存在');
//                   return false;
//               }
//        },"json");
       
//        if($('#time_check').val() == 0)
//        {
//            alert('推荐时间已存在');
//            return false;  
//        }
        
//        var startTime=$("#indexmanage-recommend_starttime").val();  
//        var start=new Date(startTime.replace("-", "/").replace("-", "/"));  
//        var endTime=$("#indexmanage-recommend_endtime").val();  
//        var end=new Date(endTime.replace("-", "/").replace("-", "/"));  
//        if(end<start){  
//            alert('结束时间不能小于开始时间');
//            return false;  
//        }
//        if($('#indexmanage-type').val() == 3 && $.trim($('#indexmanage-sort').val()) == '' )
//        {
//            alert('排序不能为空');
//            return false;  
//        }

        return true;  
    });  
    

</script>
<?php $this->endBlock(); ?>